package com.tianma315.admin.check.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.common.base.CoreServiceImpl;
import org.springframework.stereotype.Service;

import com.tianma315.admin.check.dao.CheckTypeDao;
import com.tianma315.admin.check.domain.CheckTypeDO;
import com.tianma315.admin.check.service.CheckTypeService;

/**
 * 
 * <pre>
 * 检查类型
 * </pre>
 * <small> 2019-05-25 10:03:07 | Aron</small>
 */
@Service
public class CheckTypeServiceImpl extends CoreServiceImpl<CheckTypeDao, CheckTypeDO> implements CheckTypeService {

    @Override
    public Page<CheckTypeDO> getCheckTypePage(Integer pageNumber, Integer pageSize, CheckTypeDO checkTypeDTO) {
        // 查询列表数据
        Page<CheckTypeDO> page = new Page<>(pageNumber, pageSize);

        Wrapper<CheckTypeDO> wrapper = new EntityWrapper<CheckTypeDO>();
        wrapper.eq("state",0);
        wrapper.like("type_name",checkTypeDTO.getTypeName());
        wrapper.orderBy("check_type_id",false);
        page = selectPage(page, wrapper);
        int total = selectCount(wrapper);
        page.setTotal(total);
        return page;
    }

    @Override
    public Boolean addCheckType(CheckTypeDO checkTypeDO) {
        checkTypeDO.setState(0);
        return insert(checkTypeDO);
    }

    @Override
    public Boolean deleteCheckType(Integer id) {
        CheckTypeDO checkTypeDO = new CheckTypeDO();
        checkTypeDO.setState(1);
        checkTypeDO.setCheckTypeId(id);
        return updateById(checkTypeDO);
    }
}
